define(['backbone', 'underscore', 'jsonview', 'jquery'], function(Backbone, _, jsonview, $) {

  function main() {
    require(['v/graph/data/province'], app);
  }

  function app(province) {
    var $app = $('<div id="app">');
    $('#main').html($app);
    var url = 'http://a.uyuntest.cn:7700/api/dataset/data/68f9bbf663574f2ba44560cac428426e';
    build($app, url, 0);

  }

  function build($elem, url, page) {
    $.get(url + '?page=' + page, getTable($elem), 'json')
  }

  function getTable($elem) {
    return function(data) {
      var $table = $('<table>').addClass('table');
      _.map(data.data.collection, getRow($table));
      $elem.append($table);
    }
  }

  function getRow($table) {
    return function(row, index) {
      var $tr = $('<tr>');
      _.map(row, getLine($tr));
      $table.append($tr);
    }
  }

  function getLine($tr) {
    return function(val, key) {
      $tr.append($('<td>').append(val))
    }
  }

  return main;
})
